function U = Extent_x(u, boundary_condition, boundary_length)
% U = Extent_x(u, boundary_condition, boundary_length)
% 
% This function extents the input 2D image u according to the
% boundary_condition by a boundary of length boundary_length but only in 
% the first direction. Possible boundary conditions are zero, constant, 
% periodic, symmetric.
% 
% See also: Extent
%
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------
    
    H = boundary_length;
    
    U = zeros(size(u) + [2*H 0]);
    U(1+H : end-H, :) = u;
      
    switch boundary_condition
        case 'zero'
            
        case 'constant'
            if H > 1
                U(1:H, :)         = kron(u(1, :), ones(H,1));
                U(end-H+1:end, :) = kron(u(end,:), ones(H,1));
            else
                U(1, :)           = u(1, :);
                U(end, :)         = u(end,:);
            end
                        
        case 'periodic'
            U(1:H, :)         = u(end-H+1:end, :);
            U(end-H+1:end, :) = u(1:H, :);
            
        case 'symmetric'
            U(1:H, :)         = flipud(u(2:H+1, :));
            U(end-H+1:end, :) = flipud(u(end-H:end-1, :));
            
        otherwise
            error('Choice of boundary condition unavailable')
    end
end